import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    DelDataButton,
    ExecuteButton,
    SelectExcelButton,
    TestDetailsButton,
    ModDataButton,
    OpenSelection,
} from '../Common/options'
import { LabHandleType, ProjectList } from '../Common/Conversion'

export const LabCoverProtector = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const labHandleType = await LabHandleType()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'detectionTime@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            // 批量审核
            Permission.findIndex(v => v.uuid === '54706ae7-587d-4556-ae75-b191845edcc1') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量审核"
                    data={{
                        type: 'SelectLabAuditStatus',
                        value2: 'LabCoverProtectorMapping',
                        url: 'posUpdateAuditStatus',
                    }}
                />
            ),
            // 批量填写原因
            Permission.findIndex(v => v.uuid === '63f6121a-f5e8-4386-848e-c2241cd24d70') !== -1 && (
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量填写原因"
                    data={{
                        type: 'SelectLabHandleType',
                        handle: labHandleType,
                        value2: 'LabCoverProtectorMapping',
                        url: 'posUpdateLabHandleType',
                    }}
                />
            ),
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getLabCoverProtectorExcel']}
            />,
        ],

        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'LabCoverProtector' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            {
                ...commonTableList.organizationUuid,
                valueEnum: ClientData.organization,
                width: 200,
                hideInModify: true,
            },
            {
                dataIndex: 'componentName',
                title: '构件名称',
                valueType: 'input',
                width: 200,
                ellipsis: true,
            },

            {
                dataIndex: 'structureName',
                title: '结构物名称',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'structuralPosition',
                title: '结构位置',
                valueType: 'input',
                width: 150,
            },

            {
                dataIndex: 'detectionTime',
                title: '检测时间',
                valueType: 'input',
                width: 180,
                hideInSearch: true,
            },
            {
                dataIndex: 'designThickness',
                title: '设计厚度(mm)',
                valueType: 'input',
                width: 120,
                hideInSearch: true,
            },
            {
                dataIndex: 'numberOfbars',
                title: '测点总数',
                valueType: 'input',
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'averageThickness',
                title: '平均厚度',
                valueType: 'input',
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'minThickness',
                title: '最小厚度',
                valueType: 'input',
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'maxThickness',
                title: '最大厚度',
                valueType: 'input',
                width: 100,
                hideInSearch: true,
            },

            {
                dataIndex: 'percentOfPass',
                title: '合格率(%)',
                valueType: 'input',
                hideInModify: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'gradingresults',
                title: '评定结果',
                valueType: 'select',
                valueEnum: BuiltInData.gradingresults,
                width: 150,
            },
            {
                dataIndex: 'labHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                ellipsis: true,
                valueEnum: labHandleType,
                hideInModify: true,
                width: 180,
            },
            {
                dataIndex: 'remark',
                title: '说明',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                ellipsis: true,
                width: 400,
            },
            {
                dataIndex: 'handleUserName',
                title: '填报人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'handleTime',
                title: '填报时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditStatus',
                title: '审核状态',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditor',
                title: '审核人',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'auditDate',
                title: '审核时间',
                hideInModify: true,
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                ...commonTableList.isEnabled,
                rules: true,
                hideInModify: true,
            },
            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                width: 250,
                hideInSearch: true,
            },
            {
                dataIndex: 'equipmentName',
                title: '设备名称',
                valueType: 'input',
                width: 400,
            },
            commonTableList.BeginStatDate,
            commonTableList.EndStatDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, isEnabled } = record
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <TestDetailsButton
                            key="test"
                            title="试验详情"
                            OptionsEvent={OptionsEvent}
                            data={{
                                type: 'LabCoverProtector',
                                title: '钢筋保护层详情',
                                data: { uuid },
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === '634a8aa9-c7ae-42f2-95bf-455ce766e895') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="patLabCoverProtector"
                                    path={[uuid, 1]}
                                    tips="数据启用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '634a8aa9-c7ae-42f2-95bf-455ce766e895') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="禁用"
                                    danger={true}
                                    url="patLabCoverProtector"
                                    path={[uuid, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '9253cc14-dc2e-43db-9bf6-c730bcbed5c7') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
